<template>
  <div>
    <!-- 签到  赚取勋章 -->
    <div class="activity">
      <div class="integral" @click="signClick">
        <div class="integral-get">
          <p class="sign">签到领积分</p>
          <p class="sing-more">连续签到领更多积分</p>
        </div>
        <img src="https://gw.alicdn.com/tfs/TB14FXwOgHqK1RjSZFkXXX.WFXa-84-84.png" alt>
      </div>
      <div class="middle"></div>
      <div class="medal">
        <div class="integral" @click="openLink">
          <div class="integral-get">
            <p class="sign">做任务赚勋章</p>
            <p class="sing-more">海量任务等你来完成</p>
          </div>
          <img src="https://gw.alicdn.com/tfs/TB1XYRwOkvoK1RjSZFwXXciCFXa-84-84.png" alt>
        </div>
      </div>
    </div>
    <!-- 签到弹窗 -->
    <div class="dialog" v-if="isShow">
      <div class="make" @touchmove.prevent></div>
      <div class="dialog-conent" @touchmove.prevent>
        <div class="list-name">
          <img
            :src="info.portrait?info.portrait:'https://gw.alicdn.com/tfs/TB15Q0lOmzqK1RjSZFHXXb3CpXa-400-400.png'"
            alt
          >
          <p>{{info.user_name}}</p>
        </div>
        <div class="dialog-num">
          <p>您已经连续签到{{sing.day_num}}天</p>
          <p>继续加油</p>
        </div>
        <div style="text-align: center;">
          <div class="dialog-btn" @click="isShow=!isShow">知道了</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { signIn } from "@/api/home";
export default {
  name: "SignItem",
  data() {
    return {
      isShow: false,
      sing: [],
      info: {}
    };
  },
  methods: {
    signClick() {
      this.sign();
    },
    openLink() {
      this.$router.push("/GainHome");
    },
    async sign() {
      try {
        let userid = {};
        if (localStorage.user) {
          userid = JSON.parse(localStorage.getItem("user"))
        }
        let parment = {
          user_id: userid.id,
          company_id: userid.company_id
        };
        let res = await signIn(parment);
        this.sing = res.data.data;
        if (res.data.status == 100) {
          this.isShow = true;
        }
      } catch (error) {
        if (error.data.status == 101) {
          this.$toast("您今天的签到次数已达上限");
        }
      }
    }
  },
  created() {
    setTimeout(() => {
      
      if (localStorage.user) {
        this.info = JSON.parse(localStorage.getItem("user"));
    }
    }, 1000);
  }
};
</script>

<style lang="scss" scoped>
@import "sign";
</style>
